package com.example.springbootproject.filter;


import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * 自定义Filter
 */
@WebFilter(filterName = "myFilter",urlPatterns = "/testFilter")
//@WebFilter(filterName = "myFilter",urlPatterns = "/*")
public class MyFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("init");
        Filter.super.init(filterConfig);
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        /**
         * 此处可以做的操作有：
         *      所有请求 检查session是否过期，过期重定向到登录页
         */
        System.out.println("myFilter");
        chain.doFilter(request,response);
    }

    @Override
    public void destroy() {
        System.out.println("destroy");
        Filter.super.destroy();
    }
}
